package com.morningstar.authorization.controller;

import cn.dev33.satoken.stp.SaTokenInfo;
import com.morningstar.authorization.controller.enitity.LoginEntity;
import com.morningstar.authorization.service.LoginService;
import com.morningstar.common.base.BaseController;
import com.morningstar.common.result.Result;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 页面用户登录
 *
 * @author Admin
 */
@Slf4j
@RestController
public class LoginController extends BaseController {

    @Resource
    LoginService loginService;

    /**
     * 用户登录
     *
     * @param loginEntity 用户登录实体
     * @return token
     * @throws Exception 异常信息
     */
    @PostMapping("/auth/login")
    public Result<SaTokenInfo> login(@RequestBody @Validated LoginEntity loginEntity) throws Exception {
        return loginService.login(loginEntity);
    }

    /**
     * 用户登出
     *
     * @return 基本结果类
     */
    @PostMapping("/auth/logout")
    public Result<Object> logout() {
        loginService.logout();
        return Result.successNoData();
    }
}
